<!--
 * @Descripttion: 单选框
 * @Author: zhoujj
 * @Date: 2021-07-05 15:50:48
 * @LastEditors: zhoujj
 * @LastEditTime: 2022-05-25 14:18:59
-->
<template>
  <div v-if="item">
    <el-form ref="form" :rules="rules" :model="form" label-width="120px">
      <el-form-item :label="item.title" prop="value">
        <el-radio-group v-model="form.value" @change="getVal">
          <el-radio
            :label="val.value"
            v-for="(val, index) in item.selectData"
            :key="index"
            >{{ val.label }}</el-radio
          >
        </el-radio-group>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
    export default {
        props: ['item', 'number'],
        data () {
            return {
                form: {
                    value: ''
                },
                rules: {
                    value: [
                        { required: this.item.must, message: this.item.msg, trigger: 'blur' }
                    ]
                }
            }
        },
        methods: {
            getVal (val) {
                if (val.length !== 0) {
                    this.$refs.form.clearValidate()
                }
                this.form.value = val
                this.$emit('changeComponent', {
                    number: this.number,
                    type: this.item.type,
                    value: this.form.value
                })
            }
        },
        mounted () {
            this.form = {
                ...this.form,
                ...this.item
            }
        }
    }
</script>

<style></style>
